﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using DocumentsTagger.BL;
using DocumentsTagger.DAL;
using System.IO;
using System.ComponentModel;
using System.Windows;
using System.Windows.Input;
using System.Windows.Threading;
using DocumentsTagger.UI.Commands;

namespace DocumentsTagger.UI.ViewModel
{
    /// <summary>
    /// the view model for the scanner option UI window.
    /// </summary>
    public class ScannerOptionsViewModel : DependencyObject
    {
        #region members
        private readonly Dispatcher r_CurrentDispatcher;
        private readonly TaggerBL r_TaggerBL = new TaggerBL(TaggerXMLDal.GetInstance());
        #endregion

        #region properties
        /// <summary>
        /// gets or sets the currently watched directories
        /// </summary>
        public ObservableCollection<string> WatchedDirectories { get; set; }
        
        /// <summary>
        /// gets or sets the command for handling the reuest of adding a directory to watch
        /// </summary>
        public ICommand AddToWatchedDirectoriesComand { get; set; }
        
        /// <summary>
        /// gets or sets the command for handling the reuest of removing a watch directory
        /// </summary>
        public ICommand RemoveFromWatchedDirectoriesComand { get; set; }
        
        /// <summary>
        /// gets or sets the currently watched direcotry
        /// </summary>
        public string SelectedWatchedDirectory { get; set; }
        
        /// <summary>
        /// gets or sets the currently selected direcotry
        /// </summary>
        public string SelectedFileSystemDirectory { get; set; }

        /// <summary>
        /// gets the drives on this computer
        /// </summary>
        public ReadOnlyCollection<DriveInfo> GetDrives
        {
            get
            {
                return new ReadOnlyCollection<DriveInfo>(DriveInfo.GetDrives());
            }
        }
        #endregion

        #region ctor
        /// <summary>
        /// creates the Vm
        /// </summary>
        public ScannerOptionsViewModel()
        {
            r_CurrentDispatcher = Dispatcher.CurrentDispatcher;
            WatchedDirectories = new ObservableCollection<string>(r_TaggerBL.GetScannedDirectories());
            AddToWatchedDirectoriesComand = new AddWatchedDirectoryCommand(this);
            RemoveFromWatchedDirectoriesComand = new RemoveWatchedDirectoryCommand(this);
        }
        #endregion

        #region methods
        /// <summary>
        /// handles the UI request for removing a watched directory
        /// </summary>
        public void RemoveFromWatchedDirectories()
        {
            r_TaggerBL.RemoveScannedDirectory(SelectedWatchedDirectory);
            WatchedDirectories.Remove(SelectedWatchedDirectory);
        }

        /// <summary>
        /// handles the UI request for adding a watched directory
        /// </summary>
        public void AddToWatchedDirectories()
        {
            r_TaggerBL.AddScannedDirectory(SelectedFileSystemDirectory);
            WatchedDirectories.Add(SelectedFileSystemDirectory);
        }

        #endregion

        

        
        
    }
}
